|
| Contents | |
| About This Extension |
Creating realtime music remixing applications on the Web becomes even more compelling when you add the element of fading individual parts of a mix. Using this extension, not only can you easily fade in and fade out musical parts, but you can also easily fade parts from the left side of the stereo field to the right side, or vice versa. What's more, you can set up your own custom fade processes to do anything you want, including moving DHTML layers around.
| What's New in the Latest Version |
There is a dedicated version history for this extension, where you will be able to find out about the new features and possible issues with the most recent version. The version history for this extension is independent of the version history for the core Music Object API.
| Getting This Extension |
To get the "music-object-x-fades.js" JavaScript file that implements this extension, simply right-click on this link (click-and-hold for Mac users). Then, from the menu that pops up, select the 'Save Link As...' or 'Save Target As...' option and save the file as "music-object-x-fades.js" into an appropriate folder of the local copy of your Web site.
In case you have problems saving the file using the above link, the "music-object-x-fades.js" file can also be found inside the documentation's "javascript" folder, along with the "music-object.js" file.
| Dependencies |
In order to use this extension, the following JavaScript file(s) must first be sourced in...
For more information on using extensions, consult the section About Music Object Extensions.
| Reference |
| |||||||||||||||||||
| Instance Methods |
| fadeController |
|
The fadeController method lets you fade the value of the specified MIDI controller.
|
fadeController ( MidiChannel0to16 , ControllerNumber0to127 , StartValueINT , EndValueINT , FadeTimeMsINT , FadeEndCallbackFunctionorJavaScriptSTR ) |
| FadeOBJ |
The fadeController method lets you fade the value of the specified MIDI controller from a specified start value to a specified end value. This is useful for remix applications and allows you to, among other things, fade in or fade out the channel volume for a musical part, or even fade parts from the left side of the stereo field to the right side, or vice versa.
In order to perform a channel volume fade, just use the value 7 for the ControllerNumber0to127 parameter. For example, the statement
In order to perform a panning fade from left to right, you would use the value 10 for the ControllerNumber0to127 parameter. For example, the statement
For more ideas on controllers that can be faded, consult the appendix Supported MIDI Controllers.
When no FadeEndCallback parameter is specified, no additional action is performed when the fade comes to an end.
When there is also no FadeTimeMsINT parameter specified, then the value 1000 (1 second) is chosen as the default value for the fade time.
When there is also no EndValueINT parameter specified, then the value 0 is chosen as the default value for the fade's end value.
When there is also no StartValueINT parameter specified, then the current value of the specified MIDI controller is used as the fade's start value.
| fadeTempo |
|
The fadeTempo method lets you transition the song playback tempo to a new tempo over a specified time.
|
fadeTempo ( StartTempoBPM0to300 , EndTempoBPM0to300 , FadeTimeMsINT , FadeEndCallbackFunctionorJavaScriptSTR ) |
| FadeOBJ |
The fadeTempo method lets you transition the song playback tempo to a new tempo over a specified time. For example, the statement
In this example, if the current tempo of the instance wasn't already set to 120 at the time of the fade, then there might be a noticeable "hiccup" as the tempo fade is triggered. If we had no way of easily knowing the current tempo for the instance, then we could use the special value null for the StartTempoBPM0to300 parameter to indicate that the tempo fade should start at the current tempo value, as in
When no FadeEndCallback parameter is specified, no additional action is performed when the fade comes to an end.
When there is also no FadeTimeMsINT parameter specified, then the value 1000 (1 second) is chosen as the default value for the fade time.
| fadeVolumeScalar |
|
The fadeVolumeScalar method lets you fade any of the custom volume scalars that are registered for a Music Object instance.
|
fadeVolumeScalar ( VolumeScalarNameSTR , StartVolume0to100 , EndVolume0to100 , FadeTimeMsINT , FadeEndCallbackFunctionorJavaScriptSTR , FadeStepCallbackFunctionorJavaScriptSTR ) |
| FadeOBJ |
When no FadeStepCallback parameter is specified, then no handler for the onOutputVolumeChange callback will be set.
When there is also no FadeEndCallback parameter specified, then no callback will be executed when the fade reaches its conclusion.
When there is also no FadeTimeMsINT parameter specified, then the fade will have a default duration of 1 second (1000ms), which is equivalent to specifying the value 1000 for this parameter.
When there is also no EndVolume0to100 parameter specified, then the fade will have a default end volume of 0.
When there is also no StartVolume0to100 parameter specified, then the fade will start at the current volume level of the specified volume scalar.
| Static Methods |
| Music.fade |
|
The Music.fade static method lets you initiate your own custom fade process to affect anything you desire.
|
Music.fade ( FadeNameSTR , StartValueINT , EndValueINT , FadeTimeMsINT , UpdateHandlerFunctionorJavaScriptSTR , FadeEndCallbackFunctionorJavaScriptSTR , EndIfInProgressBOOL ) |
| FadeOBJ |
The FadeNameSTR parameter is a unique identifier for the fade you wish to initiate. This allows the fade to be triggered multiple times without Music Object assigning new fade tasks. This is essential if one wishes to do things like fade the tempo or fade the volume of an instance. It doesn't make all that much sense to have multiple fade tasks in progress that are all fighting with each other to set the same parameter. For instance, it wouldn't make any sense to have three separate fade tasks in progress that are fading in completely different directions, yet are all trying to set the player volume.
The UpdateHandler parameter is used to register the function or JavaScript statements you would like executed each time the fade value is updated. If you register a function as the update handler, then this function should expect to take one parameter, being the current value of the fade. If, on the other hand, you register a string statement block that is to be executed for each update, then the statements in this statement block can refer to the variable fadeValue which will be defined only for the scope of the statement block.
The FadeEndCallback parameter is used to register the function or JavaScript statements you would like executed when the fade completes. And the EndIfInProgressBOOL parameter indicates whether a pre-existing fade by the same name as that specified by the FadeNameSTR parameter should be stopped before the new fade is initiated, or whether the pre-existing fade by that name should simply be updated with the new fade settings.
Some of these principles are a little hard to explain without an example, so let's take a look at one. In the following straightforward example, we're using this method to initiate a tempo fade for the Music Object instance "myMusicObject"...
Music.fade ( 'myMusicObject_fadeTempo', 120, 200, 5000, 'myMusicObject.setTempo (fadeValue)' ); |
What we have here is a fade that is named "myMusicObject_fadeTempo", which starts fading from the value 120 and reaches the value 200 over a period of 5 seconds. And each time the fade value is updated, the JavaScript statement
Notice how we haven't specified the FadeEndCallback or EndIfInProgressBOOL parameters in this example. This is because there are variations of this method (see below) where it is not necessary to specify these parameters. Now, of course, we could have used the ready-made fadeTempo instance method to achieve the same results as we have here, but this is just an example to illustrate how the Music.fade static method is used.
When no EndIfInProgressBOOL parameter is specified, the default behavior is for the new fade to not end any pre-existing fade by the same name. The pre-existing fade will merely be updated with the new fade values.
When there is also no FadeEndCallback parameter specified, then no additional action is performed when the fade comes to an end.
| Objects |
| Music.Fade |
|
The Music.Fade object lets you store the values for a fade process and trigger the fade at any time.
|
Music.Fade ( StartValueINT , EndValueINT , FadeTimeMsINT , UpdateHandlerFunctionorJavaScriptSTR , FadeEndCallbackFunctionorJavaScriptSTR , RestoreStartValueBOOL ) |
| FadeOBJ |
The UpdateHandler parameter is used to register the function or JavaScript statements you would like executed each time the fade value is updated. If you register a function as the update handler, then this function should expect to take one parameter, being the current value of the fade. If, on the other hand, you register a string statement block that is to be executed for each update, then the statements in this statement block can refer to the variable fadeValue which will be defined only for the scope of the statement block.
The FadeEndCallback parameter is used to register the function or JavaScript statements you would like executed when the fade completes. And the RestoreStartValueBOOL parameter indicates whether or not the registered update handler should be called when the fade completes with the initial fade start value as a parameter, allowing whatever was being affected by the fade to be reset to its start value.
Following is a simple example of how the Music.Fade object could be used...
myTempoFade = new Music.Fade ( 120, 200, 5000, 'myMusicObject.setTempo (fadeValue)' ); myTempoFade.start (); |
In this example, we are creating an instance of a Music.Fade object for the purpose of fading the tempo of the Music Object instance "myMusicObject" from the value 120 to the value 200 over a period of 5 seconds. Each time the fade value is updated, the JavaScript statement
Notice how we haven't specified the FadeEndCallback or RestoreStartValueBOOL parameters in the Music.Fade constructor in this example. This is because there are variations of the constructor (see below) where it is not necessary to specify these parameters. Although we could have used the ready-made fadeTempo instance method to achieve the same results as we have here, this is just an example to illustrate how the Music.Fade object is used.
When no RestoreStartValueBOOL parameter is specified, the default behavior is for the registered update handler not to be called when the fade completes, so whatever was being affected by the fade will not be reset to its start value when the fade ends.
When there is also no FadeEndCallback parameter specified, then no additional action is performed when the fade comes to an end.